home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2000 February / Macworld (2000-02).dmg / Cool Extras! / WallBall Screen Saver / WallBall.dxr / 00006_Ball Bouncer.ls < prev    next >
Encoding:
Text File  |  1999-11-11  |  2.9 KB  |  115 lines

  1. property x, y, kTopLimit, kBottomLimit, kLeftLimit, kRightLimit
  2. global gBallSpeed, gPaused
  3.  
  4. on beginSprite me
  5.   gameBoardS = 20
  6.   velocityList = [-1.0, -0.5, 0.5, 1.0]
  7.   me.x = getAt(velocityList, random(count(velocityList)))
  8.   me.y = abs(getAt(velocityList, random(count(velocityList))))
  9.   me.kTopLimit = sprite(gameBoardS).top
  10.   me.kBottomLimit = sprite(gameBoardS).bottom
  11.   me.kLeftLimit = sprite(gameBoardS).left
  12.   me.kRightLimit = sprite(gameBoardS).right
  13. end
  14.  
  15. on exitFrame me
  16.   if gPaused = 0 then
  17.     moveBall(me)
  18.   end if
  19. end
  20.  
  21. on moveBall me
  22.   sprite(me.spriteNum).loc = sprite(me.spriteNum).loc + (point(x, y) * gBallSpeed)
  23.   checkBounds(me)
  24. end
  25.  
  26. on checkBounds me
  27.   if ((sprite(me.spriteNum).right >= me.kRightLimit) and (x > 0)) or ((sprite(me.spriteNum).left <= me.kLeftLimit) and (x < 0)) then
  28.     bounce(me, #leftright)
  29.   end if
  30.   if (sprite(me.spriteNum).top <= me.kTopLimit) and (y < 0) then
  31.     bounce(me, #updown)
  32.   else
  33.     if (sprite(me.spriteNum).bottom >= me.kBottomLimit) and (y > 0) then
  34.       sprite(me.spriteNum).member = member("BAll Explode Loop")
  35.       puppetSound("shot")
  36.       updateStage()
  37.       repeat while soundBusy(1)
  38.         updateStage()
  39.       end repeat
  40.       launchBall()
  41.     end if
  42.   end if
  43. end
  44.  
  45. on bounce me, direction
  46.   paddleS = 43
  47.   paddleQuad = sprite(paddleS).width / 4
  48.   if listp(direction) then
  49.     collisionS = getAt(direction, 1)
  50.     if the locH of sprite me.spriteNum < the locH of sprite collisionS then
  51.       direction = #rickecheLeft
  52.     else
  53.       direction = #rickecheRight
  54.     end if
  55.     if collisionS > paddleS then
  56.       exit
  57.     end if
  58.     if collisionS <= 20 then
  59.       exit
  60.     end if
  61.     if sprite(collisionS).member.name = "Exploiding Brick Loop" then
  62.       exit
  63.     end if
  64.   end if
  65.   puppetSound("Jug")
  66.   case direction of
  67.     #updown:
  68.       me.y = me.y * -1
  69.     #leftright:
  70.       me.x = me.x * -1
  71.     #rickecheLeft:
  72.       if me.x > 0 then
  73.         me.x = me.x * -1
  74.       end if
  75.       me.y = me.y * -1
  76.       if collisionS = paddleS then
  77.         animateBall(me)
  78.         if the locH of sprite me.spriteNum < (sprite(paddleS).left + (paddleQuad * 1)) then
  79.           me.x = me.x + 0.5
  80.         else
  81.           me.x = me.x - 0.5
  82.         end if
  83.         exit
  84.       end if
  85.       removeBrick(me, collisionS)
  86.     #rickecheRight:
  87.       me.x = abs(me.x)
  88.       me.y = me.y * -1
  89.       if collisionS = paddleS then
  90.         animateBall(me)
  91.         if the locH of sprite me.spriteNum < (sprite(paddleS).left + (paddleQuad * 3)) then
  92.           me.x = me.x - 0.5
  93.         else
  94.           me.x = me.x + 0.5
  95.         end if
  96.         exit
  97.       end if
  98.       removeBrick(me, collisionS)
  99.     otherwise:
  100.       me.y = me.y * -1
  101.       me.x = me.x * -1
  102.   end case
  103. end
  104.  
  105. on removeBrick me, brickS
  106.   global gBrickMax, gBrickNum
  107.   sprite(brickS).member = member("Exploiding Brick Loop")
  108.   gBallSpeed = gBallSpeed + 0.5
  109.   gBrickNum = gBrickNum + 1
  110. end
  111.  
  112. on animateBall me
  113.   puppetSound("Paddle")
  114. end
  115.